package CompleteFutureDemo;

import common.CalcTask;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;

public class AsyncTest {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        //supplyAsync表示创建带返回值的异步任务的
        CompletableFuture<Double> cf1 = CompletableFuture.supplyAsync(() -> new CalcTask().RunWithResult());
        //runAsync表示创建无返回值的异步任务
        CompletableFuture<Void> cf2 = CompletableFuture.runAsync(() -> new CalcTask().Run());


        System.out.println("主线程开始："+System.currentTimeMillis());
        System.out.println("执行结果："+ cf1.get());
        System.out.println("执行结果："+ cf2.get());
        System.out.println("主线程结束："+System.currentTimeMillis());
    }
}
